package com.mew.common.rest.events;

import com.mew.common.entity.events.Sign;
import com.mew.common.rest.MewResponse;
import com.mew.common.rest.user.UserMoneyResponseMessage;
import com.mew.common.util.PbWriteUtils;
import io.netty.buffer.ByteBuf;
import lombok.*;

import java.util.Arrays;

@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SignInfoResponseMessage extends MewResponse<SignInfoResponseMessage> {

    private int signDayNum; //当前签到 共签几天

    private long ruleA;  //3天金币
    private long ruleB;  //7天 金币
    private long ruleC;  // 14天 金币
    private long ruleD;  //28天 金币

    public int aStatus; //3天 0 表示不能领取， 1表示可以领取， 2表示已领取
    public int bStatus; //7天 0 表示不能领取， 1表示可以领取， 2表示已领取
    public int cStatus; //14天 0 表示不能领取， 1表示可以领取， 2表示已领取
    public int dStatus; //28天 0 表示不能领取， 1表示可以领取， 2表示已领取

    public String fisrt7;

    public UserMoneyResponseMessage userMoneyResponseMessage = new UserMoneyResponseMessage();  // 签到所得分数

    public int sign; //0  这把是签到 ；1  已签到

    @Override
    public void write(ByteBuf b) {

        PbWriteUtils.attr2byte(this,b);
        userMoneyResponseMessage.write(b);
        writeInt(b,sign);
    }

    @Override
    public SignInfoResponseMessage read(ByteBuf byteBuf) {
        return null;
    }

    public static SignInfoResponseMessage toMsg(Sign sign){

        int[] signInfo = Arrays.stream(sign.getSignInfo().split(",")).mapToInt(Integer::parseInt).toArray();
        //签几天
        int sum = Arrays.stream(signInfo).sum();

        SignInfoResponseMessage message = new SignInfoResponseMessage();
        message.setSignDayNum(sum);
        message.setAStatus(sign.getAStatus()==1?2:(sum>=7?1:0));
        message.setBStatus(sign.getBStatus()==1?2:(sum>=15?1:0));
        message.setCStatus(sign.getCStatus()==1?2:(sum>=22?1:0));
        message.setDStatus(sign.getDStatus()==1?2:(sum>=28?1:0));

        return message;
    }

}
